package com.dji.common.utils;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.PropertyResourceBundle;
import java.util.ResourceBundle;

public class PropertiesUtil {
	private static ResourceBundle ResourceBundle = null;
	static {
		InputStream InputStream = null;
		try {
			InputStream = new FileInputStream(SystemUtils.getClassPath() + "config.properties");
			ResourceBundle = new PropertyResourceBundle(InputStream);
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (InputStream != null) {
				try {
					InputStream.close();
				} catch (Exception e) {
				}
			}
		}
	}

	/**
	 * 获取属性值
	 * 
	 * @param key
	 * @return
	 */
	public static String getString(String key) {
		if (ResourceBundle.containsKey(key)) {
			return ResourceBundle.getString(key);
		} else {
			throw new RuntimeException("资源文件不包含key:" + key);
		}
	}

	public static int getInt(String key) {
		return Integer.parseInt(getString(key));
	}
}
